package dm.ast;

/**
 * @author weihuixin
 * @date 2024/2/29
 * @Description Dm基本数据类型
 */
public enum DmDataType {
    INT(0),
    CHAR(1),
    BINARY(2),
    TIME(3),
    INTERVAL(4),
    CLOB(5),
    BLOB(6),
    BOOLEAN(7);

    private int index = -1;

    private DmDataType(int index) {
        this.index = index;
    }

    public int getIndex() {
        return this.index;
    }

    public static DmDataType getDmDataType(String typeString) {
        if (typeString.toUpperCase().startsWith("INTERVAL"))
        {
            return DmDataType.INTERVAL;
        }
        switch (typeString.toUpperCase()) {
            case "INT":
            case "INTEGER":
            case "BIGINT":
            case "TINYINT":
            case "BYTE":
            case "SMALLINT":
            case "NUMERIC":
            case "DECIMAL":
            case "DEC":
            case "NUMBER":
            case "FLOAT":
            case "DOUBLE":
            case "REAL":
            case "ROWID": //适应v$ifun arg中参数类型为rowid
                return DmDataType.INT;
            case "CHAR":
            case "CHARACTER":
            case "VARCHAR":
            case "VARCHAR2":
                return DmDataType.CHAR;
            case "BINARY":
            case "VARBINARY":
                return DmDataType.BINARY;
            case "DATE":
            case "TIME":
            case "TIMESTAMP":
            case "DATETIME":
            case "DATETIME WITH TIME ZONE":
            case "TIME WITH TIME ZONE":
            case "TIMESTAMP WITH TIME ZONE":
            case "TIMESTAMP WITH LOCAL TIME ZONE":
                return DmDataType.TIME;
            case "TEXT":
            case "LONG":
            case "LONGVARCHAR":
            case "CLOB":
                return DmDataType.CLOB;
            case "IMAGE":
            case "LONGVARBINARY":
            case "BLOB":
                return DmDataType.BLOB;
            case "BIT":
            case "BOOLEAN":
                return DmDataType.BOOLEAN;
            default:
                //throw new AssertionError(typeString);
                System.out.println(typeString + " unrecognized,default type is char");
                return DmDataType.CHAR;
        }
    }
}
